* Import data from Excel to Stata & set time variable
	foreach x in bank_credit_to_gdp domestic_credit_to_gdp mkt_cap_to_gdp stocks_traded_to_gdp gdp_per_capita ///
		{
			clear all
			import excel "orig/world_bank/`x'.xlsx", sheet("final_series") firstrow
			reshape long var, i(country) j(year)
			rename var `x'
			save "data/`x'.dta", replace
		}
		
* Calculate fixed and predetermined FD		
	// merge FD measures with main data set
		clear all
		use "data/bank_credit_to_gdp.dta"
		foreach x in domestic_credit_to_gdp mkt_cap_to_gdp stocks_traded_to_gdp gdp_per_capita ///
			{
				merge m:m country year using "data/`x'.dta"
				drop _merge
			}		
	// calculate long-term country-level averages (period 1960-1974)
		gen period = (year >= 1960) // alternatively: 1975
		replace period = 0 if period == 1 & year > 1974 // alternatively: 1989
		foreach x in mkt_cap_to_gdp bank_credit_to_gdp domestic_credit_to_gdp stocks_traded_to_gdp {
			by country, sort: egen `x'_c = mean(`x') if period == 1 // get mean/median/iqr of (wins.) labor productivity per country (i.e., sum over all industries) in a given year
		}
		drop period
	// calculate per capita income in 1970 (alternatively: 1990)
		********* NOTE: Rajan and Zingales consider year 1980 (they have a different sample period)
		foreach x in gdp_per_capita {
			by country, sort: egen `x'_c = mean(`x') if year == 1970 // get mean/median/iqr of (wins.) labor productivity per country (i.e., sum over all industries) in a given year
		}
	// rename fixed FD variables
		rename gdp_per_capita_c fd0raw
		rename mkt_cap_to_gdp_c fd1raw
		rename stocks_traded_to_gdp_c fd2raw
		rename domestic_credit_to_gdp_c fd3raw
		rename bank_credit_to_gdp_c fd4raw
	// collapse averages by country
		collapse fd1raw fd2raw fd3raw fd4raw fd0raw, by(country)
		gen fd5raw = fd1raw + fd3raw
		gen fd6raw = fd2raw + fd4raw
	// take logs
		foreach x in 0 1 2 3 4 5 6 {
			gen fd`x' = log(fd`x'raw)
		}
	save "data/FD.dta", replace

* Calculate time-varying FD		
	// merge FD measures with main data set
		clear all
		use "data/bank_credit_to_gdp.dta"
		foreach x in domestic_credit_to_gdp mkt_cap_to_gdp stocks_traded_to_gdp gdp_per_capita ///
			{
				merge m:m country year using "data/`x'.dta"
				drop _merge
			}		
	// rename fixed FD variables
		rename mkt_cap_to_gdp vfd1raw
		rename stocks_traded_to_gdp vfd2raw
		rename domestic_credit_to_gdp vfd3raw
		rename bank_credit_to_gdp vfd4raw
		rename gdp_per_capita vfd0raw
		gen vfd5raw = vfd1raw + vfd3raw
		gen vfd6raw = vfd2raw + vfd4raw
	// take logs
		foreach x in 0 1 2 3 4 5 6 {
			gen vfd`x' = log(vfd`x'raw)
		}
	save "data/vFD.dta", replace
	